﻿// ===============================================================================
// Project Name        :    Gfw.BLL.Basic.Facilities
// Project Description :    
// ===============================================================================
// Class Name          :    AwardTax
// Namespace:          :    Gfw.BLL.Basic.Facilities
// Class Version       :    v1.0.0.0
// Class Description   :    
// CLR Version:        :    4.0.30319.17626
//Author               :    lif
// Machine             :    ADICO-PC
// Create Time         :    2012/6/24 15:19:29
// Update Time         :    2012/6/24 15:19:29
// ===============================================================================
// Copyright © lif 2012 . All rights reserved.
// ===============================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Gfw.BLL.Basic.Account;
using Gfw.BLL.Basic.ExceptionImpl;
using Gfw.Repositories.Account;
using Gfw.Repository;

namespace Gfw.BLL.Basic.Facilities
{
    /// <summary>
    /// 动态奖金税收
    /// </summary>
    public class AwardTax : IFacility
    {
        /// <summary>
        /// 纳税比例
        /// </summary>
        private const double TaxRatio = 0.02;

        private string userId;
        private double award;
        private string taxationSerialNo;
        private string awardSerialNo;
        private double tax;

        /// <summary>
        /// 动态奖金税收
        /// </summary>
        /// <param name="userId">贡献用户id</param>
        /// <param name="award">得奖金额</param>
        /// <param name="awardSerialNo">动态奖金流水号</param>
        /// <param name="taxationSerialNo">综合税收编号</param>
        public AwardTax(string userId, double award,string awardSerialNo, string taxationSerialNo)
        {
            this.userId = userId;
            this.award = award;
            this.taxationSerialNo = taxationSerialNo;
            this.awardSerialNo = awardSerialNo;
            tax = Math.Round(award*TaxRatio, 2);
        }

        public double IndividualAward()
        {
            return award - tax;
        }

        public void Execute(UnitOfWork unitOfWork = null)
        {
            if (unitOfWork == null)
                throw new GfwTransactionInvalidException(ConstMessage.TransactionInvalid);

          
            var companyBargainRepository = new ActCompanyBargainRepository();
            //添加公司
            companyBargainRepository.AddIncome(userId, (int)CompanyTradeTypeEnum.Tax, tax, "", null, taxationSerialNo, unitOfWork);

           
        }
    }
}
